﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yuans.BinaryConfig
{
    public class StringItem : ConfigItem
    {
        public string StringValue { set; get; }
        public StringItem(string name, string str)
        {
            base.ItemName = name;
            base.ItemType = ParamType.STRING;
            this.StringValue = str;
        }
        public override string GetFriendValueDescription()
        {
            return StringValue;
        }
        public override byte[] GetItemValueRawBytes()
        {
            int strLen = this.StringValue.Length + 1; //padding '\0'
            byte[] rawAsciiBytes = new byte[strLen];

            Encoding.ASCII.GetBytes(this.StringValue).CopyTo(rawAsciiBytes, 0);

            rawAsciiBytes[strLen - 1] = 0;

            return rawAsciiBytes;
        }
    }
}
